package com.suning.sawp.service.impl.precharge;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.suning.rsc.server.http.HttpServerServiceHandler;
import com.suning.sawp.constants.PreChargeErrorConstants;
import com.suning.sawp.dto.common.ReturnMsg;
import com.suning.sawp.dto.esb.PosSendSMSReq;
import com.suning.sawp.dto.esb.PosSendSMSRtn;
import com.suning.sawp.intf.precharge.PreChargeService;

@Service("posSendSMSService")
public class PosSendSMSService extends HttpServerServiceHandler<PosSendSMSReq, PosSendSMSRtn>{

    private static final Logger LOGGER = LoggerFactory.getLogger(PosSendSMSService.class);
    
    @Autowired
    PreChargeService preChargeService;
    
    @Override
    public PosSendSMSRtn handleBizz(PosSendSMSReq req, String uid) {
        PosSendSMSRtn ret = new PosSendSMSRtn();
        if(req != null && StringUtils.isNotBlank(req.getSerialNo())){
            try{
               ret = preChargeService.posSendSMS(req.getSerialNo());
            }catch(Exception e){
                LOGGER.error("PosSendSMSService error.", e);
                ret.setRetFlag(ReturnMsg.FAIL);
                ret.setErrorCode(PreChargeErrorConstants.PRECHARGE_ERR_E999);
                ret.setErrorMessage(PreChargeErrorConstants.PRECHARGE_ERR_MAP.get(PreChargeErrorConstants.PRECHARGE_ERR_E999));
            }
        }else{
            ret.setRetFlag(ReturnMsg.FAIL);
            ret.setErrorCode(PreChargeErrorConstants.POS_SMS_ERR_E005);
            ret.setErrorMessage(PreChargeErrorConstants.POS_SMS_ERR_MAP.get(PreChargeErrorConstants.POS_SMS_ERR_E005));
        }
        return ret;
    }

}
